package dormousefx.fx;

import javafx.concurrent.Task;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.ProgressBarTableCell;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * This class displays the current status of tasks currently queued and executing
 * within a specific executor.
 *
 */
public class TaskTable extends TableView<Task<?>> {
    
    /**
     * Constructor.
     */
    public TaskTable(){
        init();
    }
    
    private void init(){
        TableColumn<Task<?>, String> statusCol = new TableColumn("Status");
        statusCol.setCellValueFactory(new PropertyValueFactory<Task<?>, String>(
            "state"));
        statusCol.setPrefWidth(75);

        TableColumn<Task<?>, Double> progressCol = new TableColumn("Progress");
        progressCol.setCellValueFactory(new PropertyValueFactory<Task<?>, Double>(
            "progress"));
        progressCol
            .setCellFactory(ProgressBarTableCell.<Task<?>> forTableColumn());
        
        TableColumn<Task<?>, String> descCol = new TableColumn("Task");
        statusCol.setCellValueFactory(new PropertyValueFactory<Task<?>, String>(
            "title"));

        getColumns().addAll(statusCol, progressCol, descCol);
    }
    
    public void addTask(Task<?> task){
        getItems().add(task);
    }
    
    public void dispose(){
        getItems().clear();
    }
    
    
}
